package com.program.cloudmanage.tripteam.service;


import com.program.cloudmanage.tripteam.domain.TripTeam;
import com.program.cloudmanage.tripteam.persistence.TripTeamMapper;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.region.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TripTeamService {
    @Autowired
    private TripTeamMapper tripTeamMapper;
     public TripTeamService (){}
    public List<TripTeam> showTripTeams(){
        return tripTeamMapper.showTripTeam();
    }
    public TripTeam searchTripTeam(String teamId){
         return tripTeamMapper.searchTripTeam(teamId);
    }
    public List<TripTeam> searchTripTeamByname(String name){
         return tripTeamMapper.searchTripTeamByName(name);
    }
    public void insertTripTeam(TripTeam tripTeam){
        tripTeamMapper.insertTripTeam(tripTeam.getTeamid(),tripTeam.getTeamname(),tripTeam.getIntelligence(),tripTeam.getCredit());
    }
    public void deleteTripTeam(String tripTeam)
    {
        tripTeamMapper.deleteTripTeam(tripTeam);
    }
    public void updateTripTeam(TripTeam tripTeam){tripTeamMapper.updateTripTeam(tripTeam.getTeamid(),tripTeam.getTeamname(),tripTeam.getIntelligence(),tripTeam.getCredit());}
    public void updateCredit(TripTeam tripTeam){
         tripTeamMapper.updateCredit(tripTeam.getTeamid(),tripTeam.getCredit());
    }
    public COSClient createCOSClient() {
        COSCredentials cred = new BasicCOSCredentials("AKIDNcm95ELWlzIf5byQoHb0X3W9yv5BMh2L", "Rl2CKPRNE4vt0FVsFi5W2OrQ7udPFE5w");
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setRegion(new Region("ap-nanjing"));
        clientConfig.setHttpProtocol(HttpProtocol.https);
        return new COSClient(cred, clientConfig);
    }
}
